package com.example.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
@Configuration
/**跨域设置*/
public class CornConfig {
	@Bean
	public CorsFilter corsFilter() {
		UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
		source.registerCorsConfiguration("**/", config());
		return new CorsFilter(source);
		
	}

	private CorsConfiguration config() {
		CorsConfiguration corsConfiguration = new CorsConfiguration();
		//任何的域名访问
		corsConfiguration.addAllowedOrigin("*");
		//任何的头信息
		corsConfiguration.addAllowedHeader("*");
		//任何的路径
		corsConfiguration.addAllowedMethod("*");
		
		return corsConfiguration;
	}

}
